using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.obj
{
[System.Serializable]
public  class Fight : Singleton
 {

    public cfg.role.FactionType faction ;
     public cfg.obj.EAptitudeType aptitudeType ;
     public cfg.obj.ELevelType levelType ;
     public int level ;
     public float viewDistance ;
     public float actionRadius ;
     public System.Collections.Generic.List<int> skills  = new System.Collections.Generic.List<int>();
     public cfg.fight.Attr attrs  = new cfg.fight.Attr();
     


    public const int TYPE_ID = 1650991919;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(10);
        os.WriteSize(Tag.BOOL | (1 << Tag.TAG_SHIFT));  os.WriteBool(enable);  
         os.WriteSize(Tag.INT | (2 << Tag.TAG_SHIFT));  os.WriteInt(cfgId);  
         os.WriteSize(Tag.INT | (101 << Tag.TAG_SHIFT));  os.WriteInt((int)faction);  
         os.WriteSize(Tag.INT | (102 << Tag.TAG_SHIFT));  os.WriteInt((int)aptitudeType);  
         os.WriteSize(Tag.INT | (103 << Tag.TAG_SHIFT));  os.WriteInt((int)levelType);  
         os.WriteSize(Tag.INT | (104 << Tag.TAG_SHIFT));  os.WriteInt(level);  
         os.WriteSize(Tag.FLOAT | (105 << Tag.TAG_SHIFT));  os.WriteFloat(viewDistance);  
         os.WriteSize(Tag.FLOAT | (106 << Tag.TAG_SHIFT));  os.WriteFloat(actionRadius);  
         os.WriteSize(Tag.LIST | (107 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_list_int(skills,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.BEAN | (108 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_fight_Attr(attrs,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.BOOL | (1 << Tag.TAG_SHIFT)):   enable = os.ReadBool(); break;  
             case (Tag.INT | (2 << Tag.TAG_SHIFT)):   cfgId = os.ReadInt(); break;  
             case (Tag.INT | (101 << Tag.TAG_SHIFT)):   faction = (cfg.role.FactionType)(os.ReadInt()); break;  
             case (Tag.INT | (102 << Tag.TAG_SHIFT)):   aptitudeType = (cfg.obj.EAptitudeType)(os.ReadInt()); break;  
             case (Tag.INT | (103 << Tag.TAG_SHIFT)):   levelType = (cfg.obj.ELevelType)(os.ReadInt()); break;  
             case (Tag.INT | (104 << Tag.TAG_SHIFT)):   level = os.ReadInt(); break;  
             case (Tag.FLOAT | (105 << Tag.TAG_SHIFT)):   viewDistance = os.ReadFloat(); break;  
             case (Tag.FLOAT | (106 << Tag.TAG_SHIFT)):   actionRadius = os.ReadFloat(); break;  
             case (Tag.LIST | (107 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); skills = cfg.Extensions.unmarshal_compatible_list_int(os); os = _oldOs; break; }   
             case (Tag.BEAN | (108 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); attrs = cfg.Extensions.unmarshal_compatible_cfg_fight_Attr(os); os = _oldOs; break; }   
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "Fight");
        ele.WriteStartElement("enable"); ele.WriteAttributeString("id", "1"); ele.WriteBool(enable); ele.WriteEndElement();
         ele.WriteStartElement("cfgId"); ele.WriteAttributeString("id", "2"); ele.WriteInt(cfgId); ele.WriteEndElement();
         ele.WriteStartElement("faction"); ele.WriteAttributeString("id", "101"); ele.WriteEnum(faction); ele.WriteEndElement();
         ele.WriteStartElement("aptitudeType"); ele.WriteAttributeString("id", "102"); ele.WriteEnum(aptitudeType); ele.WriteEndElement();
         ele.WriteStartElement("levelType"); ele.WriteAttributeString("id", "103"); ele.WriteEnum(levelType); ele.WriteEndElement();
         ele.WriteStartElement("level"); ele.WriteAttributeString("id", "104"); ele.WriteInt(level); ele.WriteEndElement();
         ele.WriteStartElement("viewDistance"); ele.WriteAttributeString("id", "105"); ele.WriteFloat(viewDistance); ele.WriteEndElement();
         ele.WriteStartElement("actionRadius"); ele.WriteAttributeString("id", "106"); ele.WriteFloat(actionRadius); ele.WriteEndElement();
         ele.WriteStartElement("skills"); ele.WriteAttributeString("id", "107"); cfg.Extensions.xml_marshal_list_int(skills,ele); ele.WriteEndElement();
         ele.WriteStartElement("attrs"); ele.WriteAttributeString("id", "108"); cfg.Extensions.xml_marshal_cfg_fight_Attr(attrs,ele); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  enable = ele.ReadBool(); break; 
                 case 2:  cfgId = ele.ReadInt(); break; 
                 case 101:  faction = ele.ReadEnum<cfg.role.FactionType>(); break; 
                 case 102:  aptitudeType = ele.ReadEnum<cfg.obj.EAptitudeType>(); break; 
                 case 103:  levelType = ele.ReadEnum<cfg.obj.ELevelType>(); break; 
                 case 104:  level = ele.ReadInt(); break; 
                 case 105:  viewDistance = ele.ReadFloat(); break; 
                 case 106:  actionRadius = ele.ReadFloat(); break; 
                 case 107:  skills = cfg.Extensions.xml_unmarshal_list_int(ele); break; 
                 case 108:  attrs = cfg.Extensions.xml_unmarshal_cfg_fight_Attr(ele); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "enable":  enable = ele.ReadBool(); break; 
                 case "cfg_id":  cfgId = ele.ReadInt(); break; 
                 case "faction":  faction = ele.ReadEnum<cfg.role.FactionType>(); break; 
                 case "aptitude_type":  aptitudeType = ele.ReadEnum<cfg.obj.EAptitudeType>(); break; 
                 case "level_type":  levelType = ele.ReadEnum<cfg.obj.ELevelType>(); break; 
                 case "level":  level = ele.ReadInt(); break; 
                 case "view_distance":  viewDistance = ele.ReadFloat(); break; 
                 case "action_radius":  actionRadius = ele.ReadFloat(); break; 
                 case "skills":  skills = cfg.Extensions.xml_unmarshal_list_int(ele); break; 
                 case "attrs":  attrs = cfg.Extensions.xml_unmarshal_cfg_fight_Attr(ele); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
